<?php
include_once 'config.php';

$con = mysql_connect($host, $user, $password);

if (!$con) {
    echo "Sorry Unable to connect with database " . mysql_error();
}

if (!mysql_select_db($dbname)) {
    die("Cannot connect to the Database " . mysql_error($link));
}

function auth($email, $password) {
    $result = mysql_query("SELECT * FROM user WHERE email='$email' AND password='$password'");
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    if (mysql_num_rows($result) == 1) 
	{
        mysql_free_result($result);
        return true;
    } 
	else 
	{
        mysql_free_result($result);
        return false;
    }
}

function user_loggedin() {
    if (isset($_SESSION['email']) && isset($_SESSION['password'])) {
        if (!auth($_SESSION['email'], $_SESSION['password'])) {
            return true;
        } else {
            return false;
        }
    }
}

?>
